#ifndef __COMMON_H__
#define __COMMON_H__

#define LIBUSB_EXIT	1//1: libusb已安装，0: libusb未安装

#define _(String) (String)//gettext(String)

#ifndef true
#define true	TRUE
#endif

#ifndef false
#define false	FALSE
#endif

#define LOG_FILE_SIZE_MAX       (10 * 1024 * 1024)//预留log存储大小
#define PRINT_LOG_MAX_SIZE_1024	2500
#define PRINT_LOG_MAX_SIZE_300	1200


#define _DBG_	//开启调试输出，屏蔽则关输出
#define _ERR_	//开启错误输出，屏蔽则关输出
#define _LOG_	//开始关键信息输出，屏蔽则关输出

#ifdef _DBG_
#define	DBG(...) printf(__VA_ARGS__)
#else
#define	DBG(...)
#endif

#ifdef _ERR_
#define	ERR(...) printf(__VA_ARGS__)
#else
#define	ERR(...)
#endif

#ifdef _LOG_
#define	LOG(...) printf(__VA_ARGS__)
#else
#define	LOG(...)
#endif

#define D_DBG(...)	\
	DBG("[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
	DBG(__VA_ARGS__)

#define D_ERR(...)	\
	ERR("[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
	ERR(__VA_ARGS__)

#define D_LOG(...)	\
	LOG("[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
	LOG(__VA_ARGS__)

typedef enum _LOG_GRADE_ENUM_
{
    ERR_LOG_GRADE = 1,
    LOG_LOG_GRADE = 2,
    DBG_LOG_GRADE = 3,
}LOG_GRADE_ENUM;

extern int ofp_print_log(char *buf, int len, LOG_GRADE_ENUM grade);
extern int ofp_print_log_time(char *buf, int len, LOG_GRADE_ENUM grade);

//简单输出信息
#define W_LOG(fmt, ... ) \
	{\
		char dbg_info[PRINT_LOG_MAX_SIZE_1024] = {0};\
		snprintf(dbg_info, PRINT_LOG_MAX_SIZE_1024, fmt, ##__VA_ARGS__);\
		ofp_print_log(dbg_info, strlen(dbg_info), LOG_LOG_GRADE);\
		LOG("%s", dbg_info);\
	}

#define W_DBG(fmt, ... ) \
	{\
		char dbg_info[PRINT_LOG_MAX_SIZE_1024] = {0};\
		snprintf(dbg_info, PRINT_LOG_MAX_SIZE_1024, fmt, ##__VA_ARGS__);\
		ofp_print_log(dbg_info, strlen(dbg_info), DBG_LOG_GRADE);\
		DBG("%s", dbg_info);\
	}

#define W_ERR(fmt, ... ) \
		{\
			char dbg_info[PRINT_LOG_MAX_SIZE_1024] = {0};\
			snprintf(dbg_info, PRINT_LOG_MAX_SIZE_1024, fmt, ##__VA_ARGS__);\
			ofp_print_log(dbg_info, strlen(dbg_info), ERR_LOG_GRADE);\
			ERR("%s", dbg_info);\
		}

//输出时间戳、文件、行号、函数
#define WD_LOG(fmt, ... ) \
	{\
		char dbg_msg_log[PRINT_LOG_MAX_SIZE_1024] = {0};\
		char dbg_info[PRINT_LOG_MAX_SIZE_300] = {0};\
		snprintf(dbg_msg_log, PRINT_LOG_MAX_SIZE_300, "[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
		snprintf(dbg_info, PRINT_LOG_MAX_SIZE_300, fmt, ##__VA_ARGS__);\
		strcat(dbg_msg_log, dbg_info);\
		ofp_print_log_time(dbg_msg_log, strlen(dbg_msg_log), LOG_LOG_GRADE);\
		LOG("%s", dbg_msg_log);\
	}

#define WD_ERR(fmt, ... ) \
	{\
		char dbg_msg_log[PRINT_LOG_MAX_SIZE_1024] = {0};\
		char dbg_info[PRINT_LOG_MAX_SIZE_300] = {0};\
		snprintf(dbg_msg_log, PRINT_LOG_MAX_SIZE_300, "[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
		snprintf(dbg_info, PRINT_LOG_MAX_SIZE_300, fmt, ##__VA_ARGS__);\
		strcat(dbg_msg_log, dbg_info);\
		ofp_print_log_time(dbg_msg_log, strlen(dbg_msg_log), ERR_LOG_GRADE);\
		ERR("%s", dbg_msg_log);\
	}

#define WD_DBG(fmt, ... ) \
	{\
		char dbg_msg_log[PRINT_LOG_MAX_SIZE_1024] = {0};\
		char dbg_info[PRINT_LOG_MAX_SIZE_300] = {0};\
		snprintf(dbg_msg_log, PRINT_LOG_MAX_SIZE_300, "[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
		snprintf(dbg_info, PRINT_LOG_MAX_SIZE_300, fmt, ##__VA_ARGS__);\
		strcat(dbg_msg_log, dbg_info);\
		ofp_print_log_time(dbg_msg_log, strlen(dbg_msg_log), DBG_LOG_GRADE);\
		DBG("%s", dbg_msg_log);\
	}

//#define DEFAULT_DBG D_DBG
#define DEFAULT_DBG(...)


#define DRV_OK		(0)
#define DRV_ERR 	(-1)

#define uint8 unsigned char
#define int8 char

#define uint16 unsigned short int
#define int16 short int

#define uint32 unsigned int
#define int32 int

#define uint8_t unsigned char
#define int8_t char

#define uint16_t unsigned short int
#define int16_t short int

#define uint32_t unsigned int
#define int32_t int




#endif

